from PIL import Image
import numpy as np
# im = np.array(Image.open("D:/素材/01.jpg"))
# a = (im.shape, im.dtype)
# b = [255, 255, 255]-im
# im = Image.fromarray(b.astype(np.uint8))
# im.save("D:/素材/01_f.jpg")
# '''灰度变换'''
# im = np.array(Image.open("D:/素材/01.jpg").convert("L"))
# im = Image.fromarray(b.astype(np.uint8))
# im.save("D:/素材/01_g0.jpg")

# im = np.array(Image.open("D:/素材/01.jpg").convert("L"))
# b = 255-im
# im = Image.fromarray(b.astype(np.uint8))
# im.save("D:/素材/01_g1.jpg")

# '''图像压缩'''
# a = np.array(Image.open("D:/素材/01.jpg").convert("L"))
# a = a*100.0/255+150.0

# im = Image.fromarray(a.astype(np.uint8))
# im.save("D:/素材/01_i0.jpg")


# '''亮度调整'''
# a = np.array(Image.open("D:/素材/01.jpg"))
# a = 255*(a/255)**0.1

# im = Image.fromarray(a.astype(np.uint8))
# im.save("D:/素材/01_j0.jpg")



'''手绘风格'''
a = np.array(Image.open("D:/素材/01.jpg").convert("L")).astype(np.float)
depth=0.05
grad= np.gradient(a)
grad_x,grad_y=grad
grad_x*=depth
grad_y*=depth

A=np.sqrt(grad_x**2+grad_y**2+1.)
uni_x=grad_x/A
uni_y=grad_y/A
uni_z=1./A

vec_el = np.pi/2.2
vec_az = np.pi/4.
dx = np.cos(vec_el)*np.cos(vec_az);
dy = np.cos(vec_el)*np.sin(vec_az);
dz = np.sin(vec_el)
b=255*(dx*uni_x+dy*uni_y+dz*uni_z)
b=b.clip(0,255)
im = Image.fromarray(b.astype(np.uint8))
im.save("D:/素材/01_shouhui.jpg")

